home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / BLAZER.PAK / BLAZER.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  285 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1995 by Borland International, All Rights Reserved
  4. //
  5. // Implementation of the main application TBlazerApp.
  6. //----------------------------------------------------------------------------
  7. #include <owl/pch.h>
  8. #include <owl/decframe.h>
  9. #include <owl/panespli.h>
  10. #include <owl/controlg.h>
  11. #include <owl/docking.h>
  12. #include <owl/combobox.h>
  13. #include <owl/statusba.h>
  14. #include <owl/timegadg.h>
  15. #include <owl/modegad.h>
  16. #include <owl/buttonga.h>
  17. #include <owl/splashwi.h>
  18. #include <owl/mailer.h>
  19. #include <owl/opensave.h>
  20. #include <owl/mci.h>
  21. #include "blazer.h"
  22.  
  23. //
  24. // Forward declarations
  25. //
  26. class TBlazerApp;
  27. class TClientWindow;
  28.  
  29. //
  30. // Globals
  31. //
  32. static TBlazerSplash* Splash;
  33.  
  34. TStatusBar*     StatusBar;
  35. TComboBox*      ListOfDrives;
  36. TBlazerApp*     Application;
  37. TClientWindow*  ClientWindow;
  38.  
  39. //
  40. // Since TBlazerApp uses three base classes with TEventHandlers, we
  41. // need to use DEFINE_RESPONSE_TABLE3 for defining the response table.
  42. // The order of the base classes listed is important (make sure TApplication
  43. // comes last).
  44. //
  45. DEFINE_RESPONSE_TABLE3(TBlazerApp, THelpFileManager, TRecentFiles, TApplication)
  46.   EV_REGISTERED(MruFileMessage, CmMruSelected),
  47.   EV_COMMAND   (CM_FILESELECT,  CmFileSelect),
  48.   EV_COMMAND   (CM_HELPABOUT,   CmHelpAbout),
  49. END_RESPONSE_TABLE;
  50.  
  51. //
  52. //
  53. //
  54. TBlazerSplash::TBlazerSplash(TDib& dib,
  55.   int width, int height, int style, uint timeOut,
  56.   const char far* title, TModule* module)
  57. :
  58.   TSplashWindow(dib, width, height, style, timeOut, title, module)
  59. {
  60.   Engine = new TMciWaveAudio("engine.wav");
  61. }
  62.  
  63. //
  64. //
  65. //
  66. TBlazerSplash::~TBlazerSplash()
  67. {
  68.   delete Engine;
  69. }
  70.  
  71. //
  72. // Initialize the base classes.
  73. // Create the mailer object.
  74. //
  75. TBlazerApp::TBlazerApp()
  76. :
  77.   THelpFileManager(HELPFILENAME),
  78.   TRecentFiles(INIFILENAME, 6),
  79.   Mailer(0)
  80. {
  81.   try {
  82.     Mailer = new TMailer;
  83.   }
  84.   catch (TXBase&) {
  85.   }
  86. }
  87.  
  88. //
  89. // Destroy the mailer object.
  90. //
  91. TBlazerApp::~TBlazerApp()
  92. {
  93.   delete Mailer;
  94. }
  95.  
  96. //
  97. // Select files to be inserted into the MRU list.
  98. //
  99. void
  100. TBlazerApp::CmFileSelect()
  101. {
  102.   TOpenSaveDialog::TData data(OFN_NOVALIDATE | OFN_NOCHANGEDIR,
  103.     "All Files (*.*)|*.*|");
  104.   if (TFileOpenDialog(GetMainWindow(), data).Execute() == IDOK)
  105.     ::Application->SaveMenuChoice(data.FileName);
  106. }
  107.  
  108. //
  109. // A choice for the MRU list has been chosen.
  110. // The parameter wp is the id of the choice.
  111. //
  112. TResult
  113. TBlazerApp::CmMruSelected(TParam1 wp, TParam2)
  114. {
  115.   const int MaxLen = 80;
  116.   TAPointer<char> text = new char[MaxLen];
  117.   GetMenuText(wp, text, MaxLen);
  118.   GetMainWindow()->MessageBox(text, "You've selected", MB_OK);
  119.   return 0;
  120. }
  121.  
  122. //
  123. // Display the About window modally by calling Execute() instead of Create().
  124. //
  125. void
  126. TBlazerApp::CmHelpAbout()
  127. {
  128.   TAboutWindow* about = new TAboutWindow(GetMainWindow());
  129.   about->Execute();
  130.   delete about;
  131. }
  132.  
  133.  
  134. //
  135. // InitMainWindow().
  136. // This function gets called because OWL needs to create a main window.
  137. // This is the ideal time to create a splash screen (before the main
  138. // window is visible).
  139. //
  140. void
  141. TBlazerApp::InitMainWindow()
  142. {
  143.   int style = TSplashWindow::CaptureMouse |
  144.               TSplashWindow::ShrinkToFit;
  145.   int timeOut = 5000;
  146.  
  147.   // create the splash screen
  148.   //
  149.   ::Splash = new TBlazerSplash(*new TDib("splslogo.bmp"), 400, 300,
  150.     style, timeOut, "", this);
  151.   ::Splash->Create();
  152.   ::Splash->UpdateWindow();
  153.  
  154.   // play the engine
  155.   //
  156.   if (::Splash->Engine)
  157.     ::Splash->Engine->Play(MCI_NOTIFY);
  158.  
  159.   // create the main window
  160.   //
  161.   ::ClientWindow = new TClientWindow();
  162.   TDecoratedFrame* frame = new TDecoratedFrame(0, "Blazer Sample Application",
  163.     ::ClientWindow, true);
  164.   frame->AssignMenu(IDM_MAINMENU);
  165.   frame->SetIcon(::Application, IDI_BIGICON);
  166.   SetMainWindow(frame);
  167.  
  168.   // create a harbor for the docking gadget windows.
  169.   //
  170.   Harbor = new THarbor(*frame);
  171.  
  172.   // create the status bar
  173.   //
  174.   ::StatusBar = new TStatusBar(frame, TGadget::Recessed, TStatusBar::SizeGrip);
  175.   frame->Insert(*::StatusBar, TDecoratedFrame::Bottom);
  176.  
  177.   // create the dockable drive control bar
  178.   //
  179.   TDockableControlBar* controlBar = new TDockableControlBar(frame);
  180.   TTextGadget* driveText = new TTextGadget(0, TGadget::None, TTextGadget::Left,
  181.     5, "Current:");
  182.   driveText->SetShrinkWrap(true, true);
  183.   controlBar->Insert(*driveText);
  184.   controlBar->Insert(*new TSeparatorGadget);
  185.  
  186.   // initialize the list of drives
  187.   //
  188.   ::ListOfDrives = new TComboBoxAsGadget(0, DrivesId, 0, 0, 50, 100,
  189.     CBS_DROPDOWNLIST | CBS_HASSTRINGS, 0);
  190.   controlBar->Insert(*new TControlGadget(*::ListOfDrives));
  191.   controlBar->SetCaption("Select Drive");
  192.   Harbor->Insert(*controlBar, alTop);
  193.  
  194.   // initialize status control bar
  195.   //
  196.   TDockableControlBar* tracker = new TDockableControlBar(frame);
  197.   tracker->Insert(*new TModeGadget(VK_NUMLOCK, "Num"));
  198.   tracker->Insert(*new TSeparatorGadget);
  199.   tracker->Insert(*new TModeGadget(VK_CAPITAL, "Cap"));
  200.   tracker->Insert(*new TSeparatorGadget);
  201.   tracker->Insert(*new TModeGadget(VK_SCROLL, "Scr"));
  202.   tracker->SetCaption("Status");
  203.   Harbor->Insert(*tracker, alBottom);
  204.  
  205.   // initialize the time status indicator
  206.   //
  207.   TDockableControlBar* timeIndicator = new TDockableControlBar(frame);
  208.   timeIndicator->Insert(*new TTimeGadget);
  209.   timeIndicator->SetCaption("Time");
  210.   Harbor->Insert(*timeIndicator, alBottom);
  211.  
  212.   // create the tools
  213.   //
  214.   TDockableControlBar* tools = new TDockableControlBar(frame);
  215.   tools->Insert(*new TButtonGadget(IDB_CONTEXTSELECT, CM_CONTEXTSELECT));
  216.   tools->Insert(*new TButtonGadget(IDB_FILESEND, CM_FILESEND));
  217.   tools->Insert(*new TSeparatorGadget);
  218.   tools->Insert(*new TButtonGadget(IDB_HELP, CM_HELPABOUT));
  219.   tools->Insert(*new TButtonGadget(IDB_EXIT, CM_EXIT));
  220.   tools->SetCaption("Tools");
  221.   tools->SetHintMode(TGadgetWindow::EnterHints);
  222.  
  223.   Harbor->Insert(*tools, alTop, 0, rpRightOf, controlBar);
  224. }
  225.  
  226.  
  227. //
  228. // InitInstance().
  229. // This function is called after the main window has been created.
  230. // This is the place to initialize the combobox for the drive letters
  231. // because we need to make sure it has been created before adding
  232. // any strings into it.
  233. //
  234. void
  235. TBlazerApp::InitInstance()
  236. {
  237.   // Initialize main window
  238.   //
  239.   TApplication::InitInstance();
  240.  
  241.   // Fill drive combobox
  242.   //
  243.   const int MaxDriveLen = 1024;
  244.   TAPointer<char> drivesToAdd = new char[MaxDriveLen];
  245.   if (::GetLogicalDriveStrings(MaxDriveLen, drivesToAdd)) {
  246.     char* aDrive = drivesToAdd;
  247.     do {
  248.       int length = strlen(aDrive) + 1;
  249.       if (::GetDriveType(aDrive) == DRIVE_FIXED) {
  250.         if (aDrive[strlen(aDrive) - 1] == '\\')
  251.           aDrive[strlen(aDrive) - 1] = 0;
  252.         ::ListOfDrives->AddString(strupr(aDrive));
  253.       }
  254.       aDrive += length;
  255.     } while(*aDrive);
  256.   }
  257.  
  258.   // Select first drive
  259.   //
  260.   if (ListOfDrives->GetCount() > 0) {
  261.     ::ListOfDrives->SetSelIndex(0);
  262.     ::ClientWindow->CbnDriveSelected();
  263.   }
  264.  
  265.   // Now done with splash screen.
  266.   //
  267.   delete ::Splash;
  268.   ::Splash = 0;
  269. }
  270.  
  271.  
  272. //
  273. // Starting point
  274. //
  275. int
  276. OwlMain(int /*argc*/, char* /*argv*/[])
  277. {
  278.   int retVal;
  279.   ::Application = new TBlazerApp;
  280.   retVal = ::Application->Run();
  281.   delete ::Application;
  282.   ::Application = 0;
  283.   return retVal;
  284. }
  285.